//
// Created by amon.huang on 2021/7/25.
//

#ifndef AMONPLAYER_JNICALL_H
#define AMONPLAYER_JNICALL_H

#include "jni.h"

#define AUDIO_SAMPLE_RATE 44100

enum ThreadMode{
    THREAD_CHILD, THREAD_MAIN
};

class JNICall {
public:
    JavaVM *javaVM;
    JNIEnv *jniEnv;
    jmethodID jPlayerErrorMid;
    jmethodID jPlayerPreparedMid;
    jmethodID jPlayerProgressMid;
    jmethodID jPlayerCompleteMid;
    jobject jPlayerObj;
    jobject jAudioInfoListener;
    jmethodID jAudioInfoMid;
    jmethodID jAudioInfoPcmMid;
    jmethodID jVideoInfoMid;

public:
    JNICall(JavaVM *javaVm, JNIEnv *jniEnv, jobject jPlayerObj);

    ~JNICall();

    void callPlayError(ThreadMode threadMode, int code, char *msg);

    void callPlayPrepared(ThreadMode threadMode);

    void callPlayProgress(ThreadMode threadMode, double currentTime, double duration) const;

    void callPlayComplete(ThreadMode threadMode) const;

    void callVideoInfo(ThreadMode threadMode, int width, int height) const;

    void callMusicInfo(ThreadMode mode, int sampleRate, int channels) const;

    void callPcmData(ThreadMode mode, const uint8_t *pcm, int dataSize) const;

    void setAudioInfoListener(jobject jListener);
};

#endif //AMONPLAYER_JNICALL_H
